package com.terry.test2.dp;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import lombok.Data;
import lombok.Getter;

import javax.xml.bind.ValidationException;

/**
 * @author 小八
 * @date 2023年02月01日15:07
 */
@Data
public class AccountNumber {
    @Getter
    private final String accountNumber;
    public AccountNumber(String accountNumber) throws ValidationException {
        //1.可通过validation  @Empty实现
        if(ObjectUtil.isEmpty(accountNumber)){
            throw new ValidationException("accountNumber不能为空");
        }
        if(!isBankCard(accountNumber)){
            throw new ValidationException("accountNumber格式不正确");
        }
        this.accountNumber = accountNumber;
    }

    /**
     * 判断是否是银行卡类型
     *
     * @param value
     * @return
     */
    public static boolean isBankCard(String value) {
        return ReUtil.isMatch("^\\d{12,}$",value);
    }
}
